<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>绑定支付宝</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <style>
        .aui-list{background: transparent;}
        .aui-list .aui-list-item{background: #fff;border-radius: .3rem;padding-top: 3px;padding-bottom: 3px;}
        .aui-list .aui-list-header{background:transparent;color: #808080;justify-content:left;}
    </style>
</head>
<body>
    <div class="aui-content-padded aui-margin-b-15">
	    <ul class="aui-list aui-form-list">
	        <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label-icon">
                        <i class="aui-iconfont aui-icon-my"></i>
                    </div>
                    <div class="aui-list-item-input">
                        <input type="text" id="real_name" placeholder="真实姓名">
                    </div>
                </div>
            </li>
            <li class="aui-list-header"></li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label-icon">
                        <i class="aui-iconfont aui-icon-mobile"></i>
                    </div>
                    <div class="aui-list-item-input">
                        <input type="text" id="alipay_account" placeholder="支付宝账号" >
                    </div>
                </div>
            </li>
            <li class="aui-list-header"></li>
	        <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label-icon">
                        <i class="aui-iconfont aui-icon-lock"></i>
                    </div>
                    <div class="aui-list-item-input">
                        <input type="tel" placeholder="请输入手机验证码" autocomplete="off" id="smscode" maxlength="5">
                    </div>
                    <div class="aui-list-item-label aui-margin-r-5" style="width: 8rem;">
                        <div class="aui-btn codebtn1" style="width: 6rem;color: #999;" id="getcode" onclick="SendSms()">获取验证码</div>
                        <div class="aui-btn codebtn2 aui-hide" style="width: 6rem;color: #999;" id="codejqs">计时器</div>
                    </div>
                </div>
            </li>
	    </ul>
	</div>
    
	<section class="aui-content-padded">
        <div class="aui-padded-15 aui-margin-t-15"><div class="aui-btn aui-btn-danger aui-btn-block bg-dark sub jb" style="border-radius: 2.5rem;" onclick="Submit()">保存</div></div>
    </section>
</body>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript">
    apiready = function(){
        api.parseTapmode();
        getCfg();
    };
    function getCfg(){
    	_Ajax(window.APIServer.DrawCfg,'post',{},'json',function(ret){
    		if (ret.code==1) {
    			$('#real_name').val(ret.data.alipay_name);
    			$('#alipay_account').val(ret.data.alipay_account);
    		}else{
    			_toast('拉取信息失败');
    		}
    	})
    }
    //提交
    function Submit(){
    	var real_name = $api.byId('real_name').value;
    	var alipay_account = $api.byId('alipay_account').value;
    	var smscode = $api.byId('smscode').value;
    	if (smscode<=0) {
    		_toast('请输入验证码');
    		return false;
    	}
    	_loading('加载中','',true);
        _Ajax(window.APIServer.BindAlipay,'post',{values:{real_name:real_name,alipay_account:alipay_account,smscode:smscode}},'json',function(ret){
        	_loading_close();
            if (ret.code==1) {
                _toast(ret.msg);
                 //广播事件：用户登录成功
                _SendEvent('bind_alipay');
                setTimeout(function() {
                     api.closeToWin({
                         name : 'wallet_frm'
                     });
                }, 500)
            }else{
                _toast(ret.msg);
            }

        });
    }
    //获取验证码
    function SendSms(){
    	_Ajax(window.APIServer.BindAlipay,'post',{values:{type:1}},'json',function(ret){
    		if (ret.code==1) {
    			showtime(60);
    		}else if(ret.code==2){
                _toast(ret.msg);
                openPublic(JSON.stringify({title:'绑定手机',framename:'bind_mobile_frm',referer_frame:'bind_alipay_frm'}));
            }else{
                _toast(ret.msg);
            }
    	});

    }
    //.计时器
	function showtime(t) {
		for ( i = 1; i <= t; i++)
		{
			window.setTimeout("update(" + i + "," + t + ")", i * 1000);
		}
	}
	function update(num, t) {
		if (num == t) {
			$api.addCls( $api.dom( '.codebtn2' ), 'aui-hide' );
			$api.removeCls( $api.dom( '.codebtn1' ), 'aui-hide' );
			$api.text($api.byId("getcode"), '重新获取');
		}
		else
		{
			printnr = t - num;
			$api.addCls( $api.dom( '.codebtn1' ), 'aui-hide' );
			$api.removeCls( $api.dom( '.codebtn2' ), 'aui-hide' );
			$api.text($api.byId("codejqs"), '('+printnr + " 's)");
		}
	}
</script>
</html>